import boto3
import asyncio
from ecr_billing_tools import generate_date_range
import ecr_billing_link_cur
import ecr_billing_monthly_patch_ob
import ecr_billing_sync_to_customer_cur

s3 = boto3.client('s3')

billing_system_url = ""
billing_system_username = ""
billing_system_password = ""
billing_system_sub_cust_list = []
billing_system_month, last_cur_prefix_month = generate_date_range() 
last_cur_bucket = ''
last_cur_prefix_base = ''
link_cur_bucket = ''
link_cur_prefix_base = ''
manifest_json_name = ''
# OB 接收 CUR 桶：
customer_cur_bucket = ''

# 下载 Link CUR 文件，并上传到 S3 上
asyncio.run(ecr_billing_link_cur.download(billing_system_url, billing_system_username, billing_system_password, billing_system_month, billing_system_sub_cust_list, link_cur_bucket, link_cur_prefix_base, s3))

# 根据 S3 上的 Link CUR 文件，制作 PATCH CUR 文件，并上传到 S3 上
ecr_billing_monthly_patch_ob.process_patch(last_cur_prefix_month, last_cur_prefix_base, link_cur_prefix_base, last_cur_bucket, link_cur_bucket, manifest_json_name, s3)

# 输出同步用的 AWS CloudShell 命令
last_cur_prefix_parent = f'{last_cur_prefix_base}{last_cur_prefix_month}/'
new_last_cur_prefix = ecr_billing_monthly_patch_ob.generate_last_folder(last_cur_prefix_parent, last_cur_bucket, s3)
ecr_billing_sync_to_customer_cur.sync_to_cur_bucket_ob(last_cur_bucket, customer_cur_bucket, manifest_json_name, last_cur_prefix_parent, new_last_cur_prefix)